package com.ukee.birthday.modules.controller;

import com.ukee.birthday.common.utils.R;
import com.ukee.birthday.modules.entity.SysMenuEntity;
import com.ukee.birthday.modules.service.ShiroService;
import com.ukee.birthday.modules.service.SysMenuService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;

/**
 * 系统菜单
 */

@RestController
@RequestMapping("/sys/menu")
public class SysMenuController extends AbstractController{

    @Autowired
    private SysMenuService sysMenuService;
    @Autowired
    private ShiroService shiroService;

    /**
     * 导航菜单
     * @return
     */
//    @GetMapping("/nav")
//    public R nav(){
//        List<SysMenuEntity> menuList = sysMenuService.getUserMenuList(getUserId());
//        Set<String> permissions = shiroService.getUserPermissions(getUserId());
//        return R.ok().put("menuList",menuList).put("permissions",permissions);
//    }

    /**
     * 所以菜单列表
     */
    @GetMapping("/list")
    @RequiresPermissions("sys:menu:list")
    public List<SysMenuEntity> list(){
        List<SysMenuEntity> menuList = sysMenuService.list();
        for(SysMenuEntity sysMenuEntity : menuList){
            SysMenuEntity parentMenuEntity = sysMenuService.getById(sysMenuEntity.getParentId());
            if(parentMenuEntity != null){
                sysMenuEntity.setParentName(parentMenuEntity.getName());
            }
        }

        return menuList;
    }


}
